package cn.kgc.vue.controller;

import cn.kgc.vue.commons.QueryCondition;
import cn.kgc.vue.entity.Score;
import cn.kgc.vue.response.ResponseResult;
import cn.kgc.vue.service.ScoreService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @author 课工场
 * @date 2024/10/7
 * @description
 */
@RestController
@RequestMapping("score")
public class ScoreController {

    @Resource
    private ScoreService scoreService;

    @PostMapping("page")
    public ResponseResult scorePage(@RequestBody QueryCondition<Score> queryCondition){
        return scoreService.scorePage(queryCondition);
    }

    @PostMapping("addOrUpdate")
    public ResponseResult addOrUpdateScore(@RequestBody Score score){

        scoreService.saveOrUpdate(score);

        return ResponseResult.success();
    }

    @DeleteMapping("delete/{id}")
    public ResponseResult deleteScore(@PathVariable("id") Integer id){

        scoreService.removeById(id);
        return ResponseResult.success();
    }


    @PostMapping("import")
    public ResponseResult importScore(MultipartFile file){

        if (file.isEmpty()){
            return  ResponseResult.fail().message("请选择文件");
        }

       return scoreService.importScore(file);

    }

    @PostMapping("export")
    public void exportScore(@RequestBody Map<String,Object> params, HttpServletResponse response){

        scoreService.exportScore(params,response);
    }
}
